package com.java8feature.nio;

import java.io.IOException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Set;

/**
 * @description:todo
 * @auth yangzhiwei
 * @date 2021-07-30 23:27
 */

public class SelectorTest {
    public static void main(String[] args) throws IOException {

        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        SocketChannel socketChannel = serverSocketChannel.accept();


        //@MagicConstant()
        Selector selector = Selector.open();
        selector.select();
        socketChannel.register(selector, SelectionKey.OP_ACCEPT);
        /** 这个集合的每个成员都是相关的通道被选择器判断为已经准备好的*/
        Set set = selector.keys();
        selector.isOpen();
        selector.provider();
        /** 已选择的键的集合 */
        Set selectKeys = selector.selectedKeys();
        selector.wakeup();



    }

}
